package com.example.madman.yuejian;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.madman.yuejian.Bean.CourseBean;
import com.example.madman.yuejian.IP.IP_Config;
import com.example.madman.yuejian.Listener.RetrofitListener;
import com.example.madman.yuejian.Model.CourseModel;

public class CourseActivity extends AppCompatActivity implements RetrofitListener<CourseBean>{
    private TextView name,time,address,need,intro;
    private ImageView course,courseback;
    private int courseid;
    private IP_Config ip_config = new IP_Config();
    private CourseModel courseModel;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course);
        courseid = getIntent().getIntExtra("courseid",1);

        initui();
        connecthttp();
        courseback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               Intent intent=new Intent(CourseActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
    private void connecthttp(){
        courseModel = new CourseModel("gson");
        courseModel.getCourseDetail(courseid,this);
    }

    private void initui(){
        name=(TextView) findViewById(R.id.text_coursename);
        time=(TextView) findViewById(R.id.text_coursetime);
        address=(TextView) findViewById(R.id.text_courseaddress);
        intro=(TextView) findViewById(R.id.text_courseintro);
        need=(TextView) findViewById(R.id.text_courseneed);
        courseback=(ImageView) findViewById(R.id.course_back);
        course=(ImageView) findViewById(R.id.dcourse_image);
    }
    @Override
    public void onSuccess(CourseBean courseBean) {
        CourseBean data=courseBean;
        name.setText(data.getCoursename());
        time.setText(data.getCoursedate());
        address.setText(data.getCourseaddress());
        intro.setText(data.getCourseinfo());
        need.setText(data.getXuzhi());
        Glide.with(this)
                .load(ip_config.IP+"/yuejian/public/static/assets/img/"+data.getCoursepic())
                .placeholder(R.drawable.club)
                .into(course);

    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(context,msg, Toast.LENGTH_SHORT).show();
    }
}
